<template>
    <avue-crud
            ref="crud"
            :page.sync="page"
            :data="tableData"
            :permission="permissionList"
            :table-loading="tableLoading"
            :option="tableOption"
            @on-load="getList"
            @row-update="handleUpdate"
            @row-save="handleSave"
            @search-change="searchChange"
            @size-change="sizeChange"
            @current-change="currentChange"
            @row-del="rowDel"
            @row-dblclick="handleRowDBLClick"
            :span-method="spanMethod"
            @refresh-change="refreshChange"
            :row-style="rowStyle">
        <template slot="type" slot-scope="scope" >
            <template v-if="scope.row.tree">
                <el-button
                        type="text"
                        @click="handleType(scope.row,scope.index)">{{scope.row.type}}
                </el-button>
            </template>
            <template v-else>
                {{scope.row.type}}
            </template>
        </template>
    </avue-crud>
</template>

<script>
import {tableOption} from '@/const/crud/admin/dict'
import {addObj, fetchList, putObj} from "@/api/admin/dict";
export default {
    name: 'sigle-dict',
    data() {
        return {
            tableLoading: false,
            // avue 设置
            tableOption: tableOption,
            // 表数据
            tableData: [],
            // 分页
            page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20 // 每页显示多少条
            },
        }
    },
    computed: {
    },
    created() {
    },
    methods: {
        // 获取字典信息
        getList(page, params) {
            this.tableLoading = true
            fetchList(Object.assign({
                p: page.currentPage,
                ps: page.pageSize
            }, params, this.searchForm)).then(response => {
                this.tableData = response.data.data.records
                this.page.total = response.data.data.total
                this.tableLoading = false;
            })
        },
        // 修改字典数据信息
        handleUpdate: function (row, index, done) {
            console.log(row);
            putObj(row).then(() => {
                this.$message.success('修改成功')
                this.getList(this.page)
                done()
            })
        },
        // 添加一条数据
        handleSave: function (row, done) {
            addObj(row).then(() => {
                this.$message.success('添加成功')
                this.getList(this.page)
                done()
            })
        },
    }
}
</script>
<style lang="scss" scoped>
</style>